gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\pca\pcademo1.m

    % PCADEMO1 demo on use of standard PCA.

% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac
% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz
% Modifications:
% 5-July-2001, V.Franc 

echo on;

% First, we load data from file and display them. Use 'creatset' to 
% interactively create your own data.
pause;  % press anykey

data=load('pcaexam1');
ppoints(data.X, data.I);

% Now, we compute orthonormal projection matrix and project the data.
pause;  % press anykey

[T, sumErr, eigv ] = spca( data.X, 2 );

Y=T*data.X;         % projection to a new space

% The second coordinate will be replaced by constant and then the data 
% will be projected back to the original space (reconstruction).
pause;  % press anykey

Y(2,:) = repmat( mean(Y(2,:)), 1 , sum(data.K));

Xrec = T' * Y;

% Finaly, we display recostructed data and the conections to the original ones.
pause;  % press anykey

hold on;
ppoints(Xrec, 2*data.I );  % display reconstructed data with another label.

for i = 1:sum(data.K),
   origP = data.X(:,i);
   recP = Xrec(:,i); 
   
   diff(i) = norm( origP-recP )^2;   % square reconstruction error
   
   plot([origP(1),recP(1)],[origP(2),recP(2)],'k');   % conection
echo off;
end

echo on;

mean(diff)     % mean value of squared lenghts of connection black lines
eigv(2)        % eigenvalue of the neglected eigenvector

echo off;